/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.domain.dept;

import com.lap.auth.domain.dept.valueobject.StatusType;
import com.lap.auth.domain.shared.errors.UserError;
import com.lap.framework.ddd.AggregateRoot;
import com.lap.framework.exception.BizException;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
 * 部门领域。
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
@EqualsAndHashCode(callSuper = false)
@Getter
public class Dept extends AggregateRoot {

  private final Integer id;
  private final Integer pid;
  private final String pidPath;
  private final String code;
  private final String name;
  private final StatusType status;
  private final String remark;
  private final Integer sortOrder;

  public Dept(
      Integer id,
      Integer pid,
      String pidPath,
      String code,
      String name,
      StatusType status,
      String remark,
      Integer sortOrder) {
    this.id = id;
    this.pid = pid;
    this.pidPath = pidPath;
    this.code = code;
    this.name = name;
    this.status = status;
    this.remark = remark;
    this.sortOrder = sortOrder;
  }

  public void canDelete(List<Dept> child) {
    if (!child.isEmpty()) {
      BizException.interrupt(UserError.DEPT_HAS_CHILD);
    }
  }

  public boolean isNew() {
    return (id == null);
  }
}
